package com.wwh.mapper;

import com.wwh.model.Post;
import com.wwh.model.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    @Select("select * from user_ ")
    List<User> findAll();

    @Insert(" insert into user_ ( name, password, created_at, updated_at ) values (#{name}, #{password}, unix_timestamp(now()), unix_timestamp(now())) ")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    public int save(User user);

    @Delete(" delete from user_ where id= #{id} ")
    public void delete(int id);

    @Select("select * from user_ where id= #{id} ")
    public User get(int id);

    @Update("update user_ set name=#{name},updated_at=unix_timestamp(now()) where id=#{id} ")
    public int update(User user);

    @Select("select * from user_ where name=#{name}")
    public User getByName(String name);

    @Select("select * from user_ where name=#{name} and password=#{password}")
    public User search(@Param("name") String name, @Param("password") String password);
}
